import { PropsRender } from "../shopMall/PropsRender";
import { BuyAlert } from "../pet/BuyAlert";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Language } from "../../../../extend/language/Language";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { ItemData } from "../../resource/info/ItemData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
type int = number;
//class BuyAndUsePropsRender
    
    export  class BuyAndUsePropsRender extends PropsRender
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ onBuyBtnClickhandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=false;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc1=_numericStepper.value;
            if (shopItemInfo) 
            {
                loc2 = shopItemInfo.unit;
                loc4 = (loc3 = shopItemInfo.tshopSell.offer == 0 ? shopItemInfo.tshopSell.price : shopItemInfo.tshopSell.offer) * loc1;
                if (loc5 = BuyAlert.checkMoney(loc2, loc4)) 
                {
                    Alert.okLabel = Language.getString(30147);
                    Alert.buttonWidth = 80;
                    loc6 = GameDefConfig.instance.getEPrictUnitName(loc2);
                    loc7 = HTMLUtil.addColor(loc1.toString(), "#FF0000");
                    loc8 = Language.getStringByParam(30148, loc7, ItemsUtil.getItemName(new ItemData(shopItemInfo.itemInfo.item.code)), loc4 + loc6);
                    Alert.show(loc8, null, Alert.OK | Alert.CANCEL, null, this.onAlertCloseHandler);
                }
            }
            return;
        }

        /* internal  */onAlertCloseHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItemAndUse, {"shopItemInfo": shopItemInfo, "amount": _numericStepper.value}));
            }
            Alert.resetToDefault();
            return;
        }
    }
